package com.example;

import com.example.service.BookService;
import com.example.service.impl.BookServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BookApp {
    //1.未使用IOC_DI
    @Test
    public void test1(){
        BookService bookService=new BookServiceImpl();
        bookService.save();
    }

    //2.使用IOC
    @Test
    public void testIOC(){
        //获取IOC容器
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");

        //获取bean
        BookService bookService = (BookService) applicationContext.getBean("bookService");
        bookService.save();
    }

    //3.IOC_DI
    @Test
    public void test(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");

        //获取bean
        BookService bookService = (BookService) applicationContext.getBean("bookService2");
        bookService.save();
    }



}
